package com.witmed.lib_base.state

import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.update

class RealContainer<STATE:UiState>(initState:STATE) :MutableContainer<STATE>{
    override fun updateRequestState(action: RequestState.() -> RequestState) {
        _requestFlow.update { action(_requestFlow.value) }
    }

    override fun updateUiState(action: STATE.() -> STATE) {
        _uiFlow.update { action(_uiFlow.value) }
    }

    private val _uiFlow= MutableStateFlow(initState)
    private val _requestFlow= MutableStateFlow(RequestState(request = false,complete = false,error = false,refresh = false,load = false))
    override val requestFlow: StateFlow<RequestState>
        get() = _requestFlow
    override val uiFlow: StateFlow<STATE>
        get() = _uiFlow
}